package day23;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class HomeWork {}

class B1{
    static int i=0;
    static int num=0;
    public static void main(String[] args) {
        calculation(0,1);
    }
    static void calculation(int a,int b){
        if(i<=9){
            i++;
            num=a+b;
            calculation(b,num);
        }else {
            System.out.println("结果:"+num);
        }
    }
}

class A3 {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\Hello.txt");
        file.createNewFile();
        if (file.isDirectory()) {
            System.out.println("是目录");
        } else {
            System.out.println("是文件");
        }
        File file1 = new File("D:\\IOTest");
        file1.mkdirs();
        try (FileInputStream fis = new FileInputStream("D:\\Hello.txt")) {
            FileOutputStream fos = new FileOutputStream("D:\\IOTest\\Hello.txt");
            byte[] buf = new byte[1];
            int len;
            while ((len = fis.read(buf)) != -1) {
                fos.write(buf, 0, len);
            }
            fos.close();
        }catch (IOException e){
            e.printStackTrace();
        }
        file.delete();
        System.out.println("剪切完成");
    }
}

class B3 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件夹路径:");
        File file = new File(sc.next());
        String[] names = file.list(((dir, name) -> {
            if(name.endsWith(".java")) {
                return true;
            }
            return false;
        }));
        if (names != null) {
            for (String name : names) {
                System.out.println(name);
            }
        }
    }
}

class A4 {
    public static void main(String[] args) {
        File file = new File("D:\\a\\abc.mp4");
        long num = file.length();
        double count = 0;
        try(FileInputStream fis = new FileInputStream("D:\\a\\abc.mp4")) {
            FileOutputStream fos = new FileOutputStream("D:\\b\\abc.mp4");
            byte[] buf = new byte[1024];
            int len;
            long start = System.currentTimeMillis();
            while ((len = fis.read(buf)) != -1) {
                fos.write(buf, 0, len);
                count=count+len;
                String jd = String.format("%.2f%%",count/num*100 );
                System.out.println("进度:"+jd);
            }
            long end = System.currentTimeMillis();
            System.out.println(end-start);
            fos.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}

class B4 {
    public static void main(String[] args) throws IOException {
        Map<Character,Integer> map = new HashMap<>();
        File f=new File("d:\\text.txt");
        if(!f.exists()){
            System.out.println("文件不存在");
        }else{
            FileInputStream fis = new FileInputStream(f);
            byte[] bs=new byte[1];
            while(fis.read(bs)!=-1) {
                if(map.containsKey((char)bs[0])){
                    map.put((char)bs[0],map.get((char)bs[0])+1);
                }
                else {
                    map.put((char)bs[0],0);
                }
            }
            for(char c : map.keySet()){
                if((65<=c&&c<=90)||(97<=c&&c<=122)){
                    System.out.print(c+"("+map.get(c)+")\t");
                }
            }
            fis.close();
        }
    }
}